package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.ReservationCountVo;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/customer/reservation")
@Api(tags = "客户预约管理")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;

    /**
     * 查询取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult<Integer> getCancelledReservationCount() {
        Integer count = customerReservationService.cancelCount();
        return success(count);
    }
    /**
     *查询每个时间段剩余预约次数
     */
    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间的剩余预约次数")
    public ResponseResult<List<ReservationCountVo>> getRemainCount(Long time){
        List<ReservationCountVo> vo = customerReservationService.getRemainCount(time);
        return success(vo);
    }

    /**
     * 新增预约
     */
    @ApiOperation("新增预约")
    @PostMapping
    public ResponseResult addInfo(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody ReservationDto reservationDto){
        customerReservationService.addInfo(reservationDto);
        return success();
    }
    /**
     * 分页查询预约
     */
    @ApiOperation("分页查询预约")
    @GetMapping("/page")
    public ResponseResult<PageResponse<ReservationVo>> getInfo(@ApiParam(value = "当前页数") @RequestParam(defaultValue = "1") Integer pageNum,
                                                 @ApiParam(value ="每页最大页码数")@RequestParam(defaultValue = "10") Integer pageSize,
                                                 @ApiParam(value = "状态") Integer status){
        PageResponse<ReservationVo> reservationVo = customerReservationService.getInfo(pageNum,pageSize,status);
        return success(reservationVo);
    }
    /**
     * 取消预约
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public ResponseResult cancel(@PathVariable Long id){
        customerReservationService.cancelByStatus(id);
        return success();
    }
}
